package com.lyf.common.exception;


import com.lyf.common.api.IErrorCode;
import com.lyf.common.api.ResultCode;

/**
 * 自定义API异常
 * @author lyf
 */
public class ApiException extends RuntimeException {
    private IErrorCode errorCode;

    public ApiException(IErrorCode errorCode) {
        super(errorCode.getMsg());
        this.errorCode = errorCode;
    }

    public ApiException(String message) {
        super(message);
        this.errorCode = ResultCode.FAILED;
    }

    /**
     * 使用统一的错误代码，扩展可变的错误提示语
     * @param errorCode
     * @param message
     *
     * @since version 1.2.4
     */
    public ApiException(IErrorCode errorCode, String message) {
        super(message);
        this.errorCode = errorCode;
    }

    public ApiException(Throwable cause) {
        super(cause);
    }

    public ApiException(String message, Throwable cause) {
        super(message, cause);
    }

    public IErrorCode getErrorCode() {
        return errorCode;
    }
}
